Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: Bump java source and target language level to java 8 #6711

Conversation

davido
Copy link
Contributor

@davido davido commented Sep 29, 2019

No description provided.

@@ -654,8 +654,8 @@ java_library(
javacopts = select({
"//:jdk9": ["--add-modules=jdk.unsupported"],
"//conditions:default": [
"-source 7",
"-target 7",
"-source 8",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we are going to drop Java 7 support?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we would like to drop Java 7 support soon.

Copy link
Contributor Author

@davido davido Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is: Java 11 doesn't support building with language level 7. Moreover, Bazel switched to using JDK 11 internally, and the console is spammed with spurious warning messages:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

in many issue trackers: [1], [2].

But I see now, that Maven build doing something similar in java/pom.xml so that this PR is incomplete:

        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.1</version>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>

But personally, I don't care about Maven. Would it be an option to remove Java 7 support for Bazel driven build, so to say merge this PR as is, but let Maven world untouched? That way all bazel friends in the wild wouldn't see these annoying warnings, for each and every java_proto_library rules in their own and transitive dependencies BUILD files.

For example in Gerrit Code Review, I am seeing these warnings dozen times:

  • During the build of protobuf itself (would be fixed in this PR)
  • During the build of rules_closure (transitive dependency of gerrit)
  • During the build of gerrit itself, should be fixed with this CL in Bazel itself

[1] bazelbuild/bazel#8772
[2] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102

Copy link
Contributor

@rafi-kamal rafi-kamal Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We don't want existing JDK 7 users to be stuck in an old version of Protobuf. But since you are saying Java 11 doesn't support building language level 7 and Bazel switched to using JDK 11, does this mean there are currently no Bazel users who are using JDK 7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize, my bad. Java 11, 13 and even 14 version still support java language level 7 (byte code major version 51).

This issue is entirely a Bazel bug (incompatibility of two Java compiler options) and should be be fixed in Bazel instead. Sorry for the noise.

Having said that, you should consider to discontinue Java 7 language level support in future Protobuf releases.

The most recent JDK 13 and upcoming JDK 14 release already issue this warning. JDK 13:

  $ cat A.java 
class A {}
  $ ~/pgm/jdk-13/bin/javac -source 7 -target 7 -parameters A.java
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: -parameters is not supported for target value 7. Use 8 or later.

JDK 14:

  $ ~/pgm/jdk-14/bin/javac -source 7 -target 7 -parameters A.java
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: -parameters is not supported for target value 7. Use 8 or later.

@davido
Copy link
Contributor Author

davido commented Oct 3, 2019

FTR: the proper fix in Bazel project is here.

davido added a commit to davido/rules_closure that referenced this pull request Oct 7, 2019
This is a workaround to suppress annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstrea, that was
rejected: [2]. moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably neeed to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and writing the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] protocolbuffers/protobuf#6711
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
davido added a commit to davido/rules_closure that referenced this pull request Oct 7, 2019
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] protocolbuffers/protobuf#6711
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
davido added a commit to davido/rules_closure that referenced this pull request Oct 7, 2019
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] bazelbuild/bazel#8772
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
alexeagle pushed a commit to davido/rules_closure that referenced this pull request Oct 11, 2019
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] bazelbuild/bazel#8772
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
alexeagle pushed a commit to bazelbuild/rules_closure that referenced this pull request Oct 11, 2019
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] bazelbuild/bazel#8772
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
sgammon pushed a commit to Bloombox/rules_closure that referenced this pull request Oct 17, 2019
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] bazelbuild/bazel#8772
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
@davido
Copy link
Contributor Author

davido commented Mar 15, 2020

//CC @Yannic.

This is the rejected attempt to drop the Java 7 (declared as dead dozen years ago) compatibility from Protobuf library. And that's why patching protobuf on fetch in rules_closure build tool chain is still needed: [1].

[1] bazelbuild/rules_closure#478

@Yannic
Copy link
Contributor

Yannic commented Mar 15, 2020

There's already a special-case for JDK 9 (which, btw, results in not setting -source 7 -target 7 for JDK 9). Why don't we change all this to set -source 7 -target 7 iff JDK 7 and -source 8 -target 8 otherwise?

    javacopts = select({
        # TODO: I think this should actually be "//java:jdk7": [], "//java:jdk8": [], "//conditions:default": ["--add-modules=jdk.unsupported"] so >= JDK 9 sets --add-modules=jdk.unsupported.
        "//java:jdk9": ["--add-modules=jdk.unsupported"],
        "//conditions:default": [],
    }) + select({
        "//java:jdk7": [
            "-source 7",
            "-source 7",
        ],
        "//conditions:default": [
            "-source 8",
            "-source 8",
        ],
    })

@davido
Copy link
Contributor Author

davido commented Mar 15, 2020

There's already a special-case for JDK 9 [...]

There no such thing as JDK9. It's dead and discontinued, so nobody really care about that configuration option.

Why don't we change all this to set -source 7 -target 7 iff JDK 7 and -source 8 -target 8 otherwise?

There is no such thing as jdk7 in Bazel: It is the dead horse and was dropped years ago:

  $ cd bazel
  $ git grep jdk7
  CHANGELOG.md:   + b95995b: Use openjdk7 as dependency for debian package of jdk7
scripts/packages/debian/BUILD:        # 0.1.2rc2-jdk7 0.1.2~rc2-jdk7
src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java:    // Allow general purpose bit 3 (data descriptor) used in jdk7 to differ.
src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java:    // Allow general purpose bit 11 (UTF-8 encoding) used in jdk7 to differ.

The whole point with backwards compatibility in protobuf, is that major byte code version:

JDK17_MAJOR_VERSION = 51

is created even if Java 8, 11, 13 and 14 and newer are used.

I'm curious, what Bazel driven project is using Protobuf and still relies on JDK 7? Can someone point me to a one single Open Source project who is doing that?

If none is doing/using that feature, can we re-consider dropping JDK7 compatibility in Protobuf project in Bazel driven build tool chain only, but keep it in Gradle and Apache Maven?

@davido
Copy link
Contributor Author

davido commented Mar 15, 2020

I uploaded a new PR: #7306.

@Yannic
Copy link
Contributor

Yannic commented Mar 15, 2020

There's already a special-case for JDK 9 [...]

There no such thing as JDK9. It's dead and discontinued, so nobody really care about that configuration option.

Then let's get rid of that configuration.

Why don't we change all this to set -source 7 -target 7 iff JDK 7 and -source 8 -target 8 otherwise?

There is no such thing as jdk7 in Bazel: It is the dead horse and was dropped years ago:

  $ cd bazel
  $ git grep jdk7
  CHANGELOG.md:   + b95995b: Use openjdk7 as dependency for debian package of jdk7
scripts/packages/debian/BUILD:        # 0.1.2rc2-jdk7 0.1.2~rc2-jdk7
src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java:    // Allow general purpose bit 3 (data descriptor) used in jdk7 to differ.
src/java_tools/singlejar/javatests/com/google/devtools/build/singlejar/ZipCombinerTest.java:    // Allow general purpose bit 11 (UTF-8 encoding) used in jdk7 to differ.

The whole point with backwards compatibility in protobuf, is that major byte code version:

JDK17_MAJOR_VERSION = 51

is created even if Java 8, 11, 13 and 14 and newer are used.

I'm curious, what Bazel driven project is using Protobuf and still relies on JDK 7? Can someone point me to a one single Open Source project who is doing that?

If none is doing/using that feature, can we re-consider dropping JDK7 compatibility in Protobuf project in Bazel driven build tool chain only, but keep it in Gradle and Apache Maven?

So all this is about is binary compatibility of protobuf.jar? I'll need to think about this for a while, but, as of now, I don't think this is something we should care about a lot for Bazel.

ptmphuong pushed a commit to ptmphuong/rules_closure that referenced this pull request Dec 9, 2022
This is a workaround to suppress this annoying warning:

  warning: -parameters is not supported for target value 1.7. Use 1.8 or later.

wenn building protobuf_java. The full story can be seen in this Bazel
issue: [1]. I tried hard to avoid the need for patching Protobuf on
fetch, by trying to remove Java 7 compatibility mode upstream, that was
rejected: [2]. Moreover, I tried hard and spent quite some time to fix
the problem in Bazel: [3], in non-invasive way, but this PR was as well
rejected. The next natural approach is to just patch the Protobuf source
during the fetch operation.

Needless to say, that the patching during the fetch has its own
disavdantages, that the patch would probably need to be updated on
every Protobuf upgrade. But what can you do? The developers are
complaining and filling the issues in every issue tracker, as here in
Gerrit Code Review project: [4].

[1] bazelbuild/bazel#8772
[3] bazelbuild/bazel#9494
[3] protocolbuffers/protobuf#6711
[4] https://bugs.chromium.org/p/gerrit/issues/detail?id=11102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants